package com.c.ctgproject.ui.other

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper
import com.c.ctgproject.adapter.PhotoVideoListAdapter
import com.c.ctgproject.base.BaseActivityV2
import com.c.ctgproject.databinding.ActivityShowImgVideoBinding
import com.c.ctgproject.utils.getGson

class ShowImgVideoActivity : BaseActivityV2() {
    private val mBinding by lazy { ActivityShowImgVideoBinding.inflate(layoutInflater) }
    private val urls by lazy { intent.getStringExtra("urls")?:"" }
    private val mList=ArrayList<String>()
    private val mAdapter= PhotoVideoListAdapter(this,mList)
    private val position by lazy { intent.getIntExtra("position",0) }
    override fun getLayout()=mBinding.root

    override fun event() {
        if(!urls.isNullOrEmpty()){
            mList.addAll(getGson().fromJson(urls,ArrayList<String>()::class.java))
        }
        val manager = LinearLayoutManager(this)
        manager.setOrientation(LinearLayoutManager.HORIZONTAL)
        mBinding.mRecyclerView.setLayoutManager(manager)
// 将SnapHelper attach 到RecyclrView
        // 将SnapHelper attach 到RecyclrView
        val snapHelper = PagerSnapHelper()
        snapHelper.attachToRecyclerView(mBinding.mRecyclerView)
        mBinding.mRecyclerView.adapter=mAdapter
        mBinding.mRecyclerView.scrollToPosition(position)
        mAdapter.notifyDataSetChanged()
    }

    override fun click() {
        //返回
        mBinding.mBackIv.setOnClickListener {
            finish()
        }
    }
}